// src/utils/http.ts
import request from '@/request/request'
import type { Result } from '@/types/result'
import qs from 'qs'

// 定义通用请求参数和数据类型
type RequestParams = Record<string, unknown>
type RequestData = Record<string, unknown>

// 封装 get 请求
export const getRequest = <T>(url: string, params?: RequestParams): Promise<Result<T>> => {
  return request.get(url, { params })
}

// 封装 post 请求
export const postRequest = <T>(url: string, data?: RequestData): Promise<Result<T>> => {
  return request.post(url, data)
}
// src/utils/http.ts
export const postRequestLogin = <T>(
  url: string,
  data?: RequestData,
  config?: {
    params?: RequestParams
  },
): Promise<Result<T>> => {
  return request.post(url, data, config)
}

export const postFormRequest = <T>(url: string, data?: RequestData): Promise<Result<T>> => {
  return request.post(url, qs.stringify(data), {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  })
}

// 封装 put 请求
export const putRequest = <T>(url: string, data?: RequestData): Promise<Result<T>> => {
  return request.put(url, data)
}

// 封装 delete 请求
export const deleteRequest = <T>(url: string, params?: RequestParams): Promise<Result<T>> => {
  return request.delete(url, { params })
}
